package com.dingqb.main.ui;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.widget.Toast;

import com.dingqb.more.R;
import com.viewpagerfrag.ChildViewPager;
import com.viewpagerfrag.FragA;
import com.viewpagerfrag.FragAdapter;

public class MultiFragActivity extends FragmentActivity {
	ViewPager viewpager;
	List<Fragment> list = new ArrayList<>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_viewpager);
		viewpager = (ChildViewPager) findViewById(R.id.viewpager);
		FragA fragA = new FragA();
		Bundle b = new Bundle();
		b.putString("f", "aaaaa");
		fragA.setArguments(b);
		list.add(fragA);
		FragA fragA1 = new FragA();
		Bundle b1 = new Bundle();
		b1.putString("f", "bbb");
		fragA1.setArguments(b1);
		list.add(fragA1);
		viewpager
				.setAdapter(new FragAdapter(getSupportFragmentManager(), list));
		viewpager.setCurrentItem(0);
		viewpager.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int arg0) {
				Toast.makeText(MultiFragActivity.this, "" + arg0, 0).show();
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
			}

			@Override
			public void onPageScrollStateChanged(int arg0) {

			}
		});

	}

}
